package org.example.base;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

public class BaseProducer {
    public static void main(String[] args) throws Exception {
        // 1、创建生产者
        DefaultMQProducer producer = new DefaultMQProducer("my-producer-group1");

        // 2、指定nameserver地址
        producer.setNamesrvAddr("192.168.2.10:9876");

        // 3、启动生产者
        producer.start();

        // 4、创建消息并发送消息
        for (int i = 0; i < 10; i++) {
            Message message = new Message("MyTopic1", "TagA", ("hello-" + i).getBytes());
            SendResult sendResult = producer.send(message);
            System.out.println(sendResult);
        }

        // 5、关闭生产者
        producer.shutdown();
    }
}
